package cn.whale.pay.web.controller;


import cn.whale.basic.utils.JSONResult;
import cn.whale.pay.dto.AlipayNotifyDto;
import cn.whale.pay.dto.PayDto;
import cn.whale.pay.service.IAliPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class PayController {

    @Autowired
    IAliPayService aliPayService;
    //支付请求
    @PostMapping("/alipay/apply")
    public void payApply(@RequestBody PayDto payDto, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        String html = aliPayService.payApply(payDto);
        response.getWriter().println(html);
    }

    //TODO
    @PostMapping("/alipay/notify")
    public String alipayNotify(AlipayNotifyDto alipayNotifyDto)  {
        return aliPayService.alipayNotify(alipayNotifyDto);
    }

}
